﻿using System;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
using Elderos.Controls;

namespace TreeBuilder.Help
{
    /// <summary>
    /// Interaction logic for HelpWindow.xaml
    /// </summary>
    public partial class HelpWindow : NavigationWindow
    {
        public HelpWindow()
        {
            InitializeComponent();
        }

        void HelpFrame_Navigated(object sender, NavigationEventArgs e)
        {
            RefreshLinks();
        }

        private void RefreshLinks()
        {
            foreach (var link in LinkPanel.Children.OfType<HyperlinkLabel>())
            {
                if (link.Uri == null) continue;
                string linkFileName = Path.GetFileName(link.Uri.OriginalString);
                string navigatedFileName = Path.GetFileName(HelpFrame.Source.OriginalString);
                link.IsActive = linkFileName == navigatedFileName;
            }
        }

        private void NavigationWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {

        }

        private void GoToPage_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Uri url = (Uri)e.Parameter;
            HelpFrame.Navigate(url);
        }

    }
}
